<template>
  <a-layout-sider
    :class="[theme, 'sider', isMobile ? null : 'shadow']"
    width="200px"
    :collapsible="collapsible"
    v-model="collapsed"
    :trigger="null"
  >
    <div :class="['logo', theme]">
      <router-link to="/dashboard">
        <!-- <img src="@/assets/logo.png"> -->
        <h1>{{systemName}}</h1>
      </router-link>
    </div>
    <i-menu
      class="menu-wrap"
      :theme="theme"
      :collapsed="collapsed"
      :menuData="menuData"
      @select="onSelect"
    />
  </a-layout-sider>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
import IMenu from './menu'

@Component({
  components: {
    IMenu
  }
})
export default class SiderMenu extends Vue {
  @Prop({
    type: Boolean,
    required: false,
    default: false
  })
  public collapsible!: boolean

  @Prop({
    type: Boolean,
    required: false,
    default: false
  })
  public collapsed!: boolean

  @Prop({
    type: Array,
    required: true,
    default: () => []
  })
  public menuData!: any[]

  @Prop({
    type: String,
    required: false,
    default: 'dark'
  })
  public theme!: boolean

  get isMobile() {
    return this.$store.state.setting.isMobile
  }
  get systemName() {
    return this.$store.state.setting.systemName
  }

  public onSelect(obj: any) {
    this.$emit('menuSelect', obj)
  }
}
</script>

<style lang="less" scoped>
.shadow {
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.1);
}
.sider {
  height: 100%;
  z-index: 10;
  background-color: #fff;
  &.light {
    background-color: #fff;
  }
  &.dark {
    background-color: #001529;
  }
  .logo {
    height: 64px;
    position: relative;
    line-height: 64px;
    padding-left: 24px;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
    overflow: hidden;
    &.light {
      background-color: #fff;
      h1 {
        color: #1890ff;
      }
    }
    &.dark {
      background-color: #002140;
      h1 {
        color: #fff;
      }
    }
    h1 {
      color: #1890ff;
      font-size: 20px;
      margin: 0 0 0 12px;
      font-family: 'Myriad Pro', 'Helvetica Neue', Arial, Helvetica, sans-serif;
      font-weight: 600;
      display: inline-block;
      height: 32px;
      line-height: 32px;
      vertical-align: middle;
    }
    img {
      width: 32px;
      display: inline-block;
      vertical-align: middle;
    }
  }
  .menu-wrap {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
  }
}
/deep/ .ant-layout-sider-children {
  display: flex;
  flex-direction: column;
}
/deep/ .ant-menu-item .anticon,
.ant-menu-submenu-title .anticon {
  font-size: 16px;
}
</style>
